#!/bin/bash
# hastily written
# but does the job
# whatever

TODO_FILE=${HOME}/.local/share/${USER}/.todo
#SIZE=$((COLUMNS - 4))

append() {
    echo "$*" >> "${TODO_FILE}"
    sort -h -o "${TODO_FILE}" "${TODO_FILE}"
}

# check existence of todo file, create if not
[ ! -f "${TODO_FILE}" ] && touch "${TODO_FILE}"

# for appending lines (removing done via 'done')
[ -n "$*" ] && append "$@" && echo "noted" && exit 0

[ $(($(wc -c < "${TODO_FILE}"))) -lt 2 ] && echo "nothing to do" && exit 0

#splitline
# iterate over lines (not words) in todo file
echo "[ -2 ] smile!"
echo "[ -1 ] virtue"
echo "[  0 ] don't forget activity, stretching, breathing exercises and cold showers :)"
index=1
while IFS=$'\n' read -r line
do
    printf "[ %2d ] " ${index}
    echo "$line"
    index=$((index + 1))
done < "${TODO_FILE}"
#splitline
